<template>
	<view class="container">
		<view class="position-relative">
			<image src="@/static/images/menu/two.jpg" class="bg" mode="widthFix"></image>
			<!-- <button type="default" size="mini" class="hym-btn" @tap="memberCode">
				<image src="/static/images/mine/hym.png"></image>
				<text>会员码</text>
			</button> -->
		</view>

		<view style="padding: 0 30rpx;">
			<!-- user box begin -->
			<view class="d-flex flex-column bg-white user-box">

				<view class="d-flex align-items-center">
					<view class="avatar">
						<image :src="member.headImg || '../../static/images/mine/default.png'"></image>
						<!-- <view class="badge" v-if="isLogin">
							<image src="/static/images/mine/level.png"></image>
							<view>{{ member.memberLevel }}</view>
						</view> -->
					</view>
					<view class="d-flex flex-column flex-fill overflow-hidden">
						<view class="font-size-lg font-weight-bold d-flex justify-content-start align-items-center">
							<view class="text-truncate" style="font-size: 23px;">{{ member.nickName || '未登录'}}</view>
							<!-- <view class="iconfont iconarrow-right line-height-100" style="font-size: 20px;margin-top: 6px;"></view> -->
						</view>
						<!-- <view class="font-size-sm text-color-assist">
							当前成长值{{ isLogin ? member.currentValue : 0 }}/{{ isLogin ? member.currentValue + member.needValue : 0 }}
						</view> -->
						<!-- <view class="w-100">
							 <progress percent="0" activeColor="rgba(141,74,50,0.7)" height="8rpx" :percent="growthValue" border-radius="8rpx"/>
						</view> -->
					</view>
					<!-- <view class="level-benefit d-flex flex-shrink-0 align-items-center justify-content-end text-color-white bg-warning font-size-sm">
						<view>会员权益</view>
						<view class="iconfont iconarrow-right line-height-100"></view>
					</view> -->
				</view>
				<!-- user grid begin -->
				<view class="w-100 d-flex align-items-center" style="justify-content: space-around;">
					<view class="user-grid">
						<view class="value font-size-extra-lg font-weight-bold text-color-base">
							{{ balance || 0}}
						</view>
						<view class="font-size-sm text-color-assist">福币余额</view>
					</view>
					<view class="user-grid">
						<view class="value font-size-extra-lg font-weight-bold text-color-base">
							{{ cost.todayCost || 0}}
						</view>
						<view class="font-size-sm text-color-assist">今日消费</view>
					</view>
					<view class="user-grid">
						<view class="value font-size-extra-lg font-weight-bold text-color-base">
							{{ cost.totalCost || 0}}
						</view>
						<view class="font-size-sm text-color-assist">累积消费</view>
					</view>

				</view>
			</view>
		</view>
		<view class="service-box">
			<view class="font-size-lg text-color-base font-weight-bold" style="margin-bottom: 20px;">其他服务</view>
			<view class="row" @tap="addresses">
				<view class="box">
					<view class="icon-left">
						<image src="../../static/images/mine-2.png"></image>
						配送地址
					</view>
					
					<view class="icon-right">
						<image src="../../static/images/mine/arrow-right.png"></image>
					</view>
				</view>

				<!-- <view class="grid" @tap="orders">
					<view class="image">
						<image src="../../static/images/mine-1.png"></image>
					</view>
					<view>历史订单</view>
				</view>
				<view class="grid" @tap="addresses">
					<view class="image">
						<image src="../../static/images/mine-2.png"></image>
					</view>
					<view>配送地址</view>
				</view> -->

			</view>
			<view class="row">
				<view class="box">
					
					<view class="icon-left">
						<image src="../../static/images/mine-1.png"></image>
						隐私政策
					</view>
					<view class="icon-right">
						<image src="../../static/images/mine/arrow-right.png"></image>
					</view>
				</view>
			</view>
			<view class="row">
				<view class="box">
					<view class="icon-left">
						<image src="../../static/images/mine-3.png"></image>
						清除缓存
					</view>
					<view class="icon-right">
						<image src="../../static/images/mine/arrow-right.png"></image>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				newIcon: 'https://img-shop.qmimg.cn/s16/images/2020/05/12/ffb0613dded704b6.png',
				isLogin: true,
				member: {},
				cost:{
					totalCost:0,
					todayCost:0,
				},
				balance:0
			}
		},
		onLoad() {
			this.$wxHide()
		},
		onShow() {
			this.getUserInfo()
			this.getUserCost()
			this.getUserBalance()
		},
		methods: {
			//获取余额信息
			getUserBalance() {
				uni.showLoading({
					title:'加载中'
				})
				this.uni_request({
					url: '/api/user/getUserBalance',
					method: 'POST',
					success: (res) => {
						uni.hideLoading()
						if (res.data.code == 0 || res.data.code == 200) {
							this.balance = Number(res.data.data)
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
					},
				})
				
			},
			//获取个人信息
			getUserInfo() {
				this.uni_request({
					url: '/api/user/getUserInfo',
					method: 'POST',
					success: (res) => {
						if (res.data.code == 0 || res.data.code == 200) {
							this.member = res.data.data
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
					},
				})
			},
			getUserCost() {
				this.uni_request({
					url: '/api/user/getUserCost',
					method: 'POST',
					success: (res) => {
						if (res.data.code == 0 || res.data.code == 200) {
							
							this.cost = res.data.data
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
					},
				})
			},
			
			login() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},

			addresses() {

				uni.navigateTo({
					url: '/pages/address/address'
				})
			},

			orders() {
				uni.navigateTo({
					url: '/pages/orders/orders'
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	page {
		height: auto;
		min-height: 100%;
		background: #f5f2f0 !important;
	}

	.bg {
		width: 100vw;
	}

	.hym-btn {
		position: absolute;
		top: 40rpx;
		right: 40rpx;
		color: $color-primary;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50rem;
		font-size: $font-size-sm;
		box-shadow: 0 0 20rpx rgba(66, 66, 66, 0.1);

		&::after {
			border: 0;
		}

		image {
			width: 30rpx;
			height: 30rpx;
			margin-right: 10rpx;
		}
	}

	.user-box {
		position: relative;
		border-radius: 8rpx;
		margin-bottom: 30rpx;
		margin-top: -115rpx;
		box-shadow: $box-shadow;
	}

	.avatar {
		position: relative;
		margin-top: -35rpx;
		margin-left: 35rpx;
		margin-right: 35rpx;
		width: 160rpx;
		height: 160rpx;
		border-radius: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #FFFFFF;
		box-shadow: 0 0 20rpx rgba($color: #000000, $alpha: 0.2);

		image {
			width: 140rpx;
			height: 140rpx;
			border-radius: 100%;
		}

		.badge {
			position: absolute;
			right: -10rpx;
			bottom: -10rpx;
			background-color: #FFFFFF;
			border-radius: 50rem;
			display: flex;
			align-items: center;
			justify-content: center;
			color: $color-warning;
			font-size: 24rpx;
			padding: 8rpx 16rpx;
			box-shadow: 0 0 20rpx rgba($color: #000000, $alpha: 0.2);

			image {
				width: 30rpx;
				height: 30rpx;
			}
		}
	}

	.level-benefit {
		margin-left: 35rpx;
		padding: 10rpx 0 10rpx 30rpx;
		border-radius: 50rem 0 0 50rem;
	}

	.user-grid {
		width: 25%;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.value {
			margin-bottom: 20rpx;
		}
	}

	.level-benefit-box {
		border-radius: 8rpx;
		margin-bottom: 30rpx;
		box-shadow: 0 10rpx 8rpx rgba($color: #878889, $alpha: 0.1);
		width: 100%;
		display: flex;
		padding: 30rpx;
		flex-direction: column;
		background-color: #FFFFFF;

		.row {
			display: flex;
			padding: 30rpx 0 20rpx;
			justify-content: space-around;
			align-items: center;

			.grid {
				width: 20%;
				display: flex;
				flex-direction: column;
				font-size: $font-size-sm;
				color: $text-color-assist;
				align-items: center;

				image {
					width: 80rpx;
					height: 80rpx;
					margin-bottom: 10rpx;
				}
			}
		}
	}

	.banner {
		width: 100%;
		border-radius: 8rpx;
		margin-bottom: 30rpx;
	}

	.service-box {
		width: 100%;
		background-color: #FFFFFF;
		padding: 20px 30rpx 0 30rpx;
		box-shadow: $box-shadow;

		.row {
			display: flex;
			flex-wrap: wrap;
			color: $text-color-assist;
			font-size: 15px;
			padding-bottom: 25px;

			.box {
				display: flex;
				align-items: center;
				justify-content: flex-start;

				.image {
					image {

						width: 50rpx;
						height: 50rpx;
					}
				}
				.icon-left{
					display: flex;align-items: center;color: $base;
					image{width: 25px;height: 25px;margin-right: 5px;}
				}
				.icon-right {
					position: absolute;
					right: 0;

					image {
						width: 50rpx;
						height: 50rpx;
					}
				}
			}

			.grid {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin-bottom: 40rpx;
				width: 25%;
				position: relative;

				.image {
					image {
						width: 60rpx;
						height: 60rpx;
						margin-bottom: 5rpx;
					}
				}

				.new-badage {
					width: 40rpx;
					height: 40rpx;
					position: absolute;
					top: 0;
					right: 30rpx;
				}
			}
		}
	}
</style>